Repository navigation
fix(parse): apply array type transform once per parse - #182
Open
shaurya703 wants to merge 1 commit into
Open
shaurya703 wants to merge 1 commit into
shaurya703 wants to merge 1 commit into
Conversation
setByType ran inside the loop over parsed keys, so a type transform was re-applied once per remaining key (aliases included), and wrapping a dot-nested option in an array mid-loop made later keys like `--env.b` land on the array instead of the object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
An option declared with
type: [fn]hasfnapplied more than once when other options are also passed:Dot-nested values on an array-typed option are also lost after the first one:
Cause
In
CAC#mri,setByType(options, transforms)is called inside the loop over parsed keys. Once the option has a value, every later iteration wraps it with[x].flat()again and re-maps it through the transform. Number-like transforms such asNumberare idempotent so this goes unnoticed, but any other transform is applied once per remaining key (aliases likec/colorcount as separate keys).For dot-nested options, the value is turned into an array after the first key, so the next
setDotPropforenv.bwritesbonto the array rather than onto the object inside it.Fix
Call
setByTypeonce, after the loop has set every value.One side effect: an option whose
defaultis set and that hastypeis now always transformed. Before, its default was transformed only when some other option happened to be passed (node bingave the raw default,node bin --verbosegave the transformed one), so the result is now the same either way.Tests
Added two tests in
tests/index.test.ts, one per case above. Both fail onmain([1431], andbmissing) and pass with the fix.pnpm vitest run(23 passed),pnpm lintandpnpm typecheckare clean.